package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.dto.SpecGroupDTO;
import com.leyou.common.dto.SpecParamDTO;
import com.leyou.item.entity.SpecGroup;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecGroupService extends ServiceImpl<SpecGroupMapper, SpecGroup> implements com.leyou.item.service.SpecGroupService {
    @Autowired
    private SpecParamService specParamService;
    @Override
    public List<SpecGroupDTO> queryGroupByCategory(Long id) {
        List<SpecParam> params = specParamService.query().eq("category_id", id).list();
        List<SpecParamDTO> paramDTOS = SpecParamDTO.convertEntityList(params);
        List<SpecGroupDTO> specGroupDTOS = SpecGroupDTO.convertEntityList(query().eq("category_id", id).list());
        for (SpecGroupDTO specGroupDTO : specGroupDTOS) {
            specGroupDTO.setParams(paramDTOS);
        }
        return specGroupDTOS;

    }
}
